//
//  @ Project : Galaxy Star Trading System
//  @ File Name : InstrumentManager.h
//  @ Date : 2014/9/5
//  @ Author :
//
//


#if !defined(_CINSTRUMENTMANAGER_H_H)
#define _CINSTRUMENTMANAGER_H_H

namespace GSTrader
{
	namespace TradeStrategy
	{
		class CTradeClient;

		struct BarItem
		{
			CTradeProvider* pTradeProvider;
			string strInstrumentId;
			string strExchangeId;
			short nBarType;
			short nBarCapacity;
		};

		class TRADE_STRATEGY_API CInstrumentManager
		{
		public:
			CInstrumentManager(CFramework* pFramework);
			virtual ~CInstrumentManager();

			CInstrument* GetInstrumentById(int nInstrumentId);
			CInstrument* GetInstrumentBySymbol(string strInstrumentId, string strExchangeId);
			bool GetAllInstrument(vector<CInstrument*>& vInstrument);

			bool AddBar(CInstrument* pInstrument, short nBarType, short nBarCapacity);
			bool AddBar(CTradeProvider* pProvider, string strInstrumentId, string strExchangeId, short nBarType, short nBarCapacity);
			bool AddBarItem(CTradeProvider* pProvider, string strInstrumentId, string strExchangeId, short nBarType, short nBarCapacity);
			
			bool AddInstrument(CInstrument* pInstrument);
			void RemoveAllBarItem();

		public:
			void OnInstrument(CMsg* pMsg);
			void OnInstrumentBegin(int nProviderId);
			void OnInstrumentEnd(int nProviderId);
			void Clear();

			bool GetInstrumentClass(int nProviderId, vector<CInstrumentClass>& vInstrumentClass);

			CSpreadInstrument* GetSpreadInstrument(int nProviderId, string strInstrumentName, int nMainLeg, int nSide, bool bAdd);
			CSpreadInstrument* GetSpreadInstrument(string strInstrumentName, int nMainLeg, int nSide);
	
			void OnTradeDisconnected(CAccountData* pAccountData);

			string m_strSpreadMarket;

		private:
			CFramework*	m_pFramework;
			vector<BarItem*> m_vBarItem;

		};
	}
}

#endif //_CINSTRUMENTMANAGER_H_H
